package nus.iss.laps.general;

import java.text.SimpleDateFormat;
import java.util.Date;

public class LapsUtil {

	
	public static Date stringToDate(String date)
	{
		try {
			SimpleDateFormat l_fmt = new SimpleDateFormat("yyyyMMdd");
			return l_fmt.parse(date);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return new Date();
	}
	
	public static String dateToString(Date date)
	{
		try {
			SimpleDateFormat l_fmt = new SimpleDateFormat("yyyyMMdd");
			return l_fmt.format(date);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "";
	}
	
	public static String formattedDateToString(String date)
	{
		try {
			SimpleDateFormat l_fmt = new SimpleDateFormat("dd/MM/yyyy");
			Date l_date = l_fmt.parse(date);
			return new SimpleDateFormat("yyyyMMdd").format(l_date);
		} catch (Exception e) {
			
		}
		return "";
	}
	
	public static String stringToFormattedDate(String date)
	{
		try {
			SimpleDateFormat l_fmt = new SimpleDateFormat("yyyyMMdd");
			Date l_date = l_fmt.parse(date);
			return new SimpleDateFormat("dd/MM/yyyy").format(l_date);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "";
	}
}
